﻿using com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx {

    [Serializable]
    public class GridLayoutGroupAdaptConfig {
        public RectOffset padding;
        public Vector2 cellSize;
        public Vector2 spacing;
        public GridLayoutGroup.Corner startCorner;
        public GridLayoutGroup.Axis startAxis;
        public TextAnchor childAlignment;
        public GridLayoutGroup.Constraint constraint;
        public int constraintCount;
        
        //重写Equals方法
        public override bool Equals(object obj) {
            if (obj == null) {
                return false;
            }

            GridLayoutGroupAdaptConfig other = (GridLayoutGroupAdaptConfig)obj;
            //对比下面属性是否一致
            if (padding.left != other.padding.left || padding.right != other.padding.right || padding.top != other.padding.top || padding.bottom != other.padding.bottom) {
                return false;
            }

            // Compare cellSize properties
            if (!cellSize.Equals(other.cellSize)) {
                return false;
            }
            
            // Compare spacing properties
            if (spacing != other.spacing) {
                return false;
            }
            
            // Compare startCorner properties
            if (startCorner != other.startCorner) {
                return false;
            }
            
            // Compare startAxis properties
            if (startAxis != other.startAxis) {
                return false;
            }
            
            // Compare childAlignment properties
            if (childAlignment != other.childAlignment) {
                return false;
            }
            
            // Compare constraint properties
            if (constraint != other.constraint) {
                return false;
            }
            
            // Compare constraintCount properties
            if (constraintCount != other.constraintCount) {
                return false;
            }

            return true;
        }
        
        //重写GetHashCode方法
        public override int GetHashCode() {
            int hash = 17;
            hash = hash * 23 + padding.GetHashCode();
            hash = hash * 23 + cellSize.GetHashCode();
            hash = hash * 23 + spacing.GetHashCode();
            hash = hash * 23 + startCorner.GetHashCode();
            hash = hash * 23 + startAxis.GetHashCode();
            hash = hash * 23 + childAlignment.GetHashCode();
            hash = hash * 23 + constraint.GetHashCode();
            hash = hash * 23 + constraintCount.GetHashCode();
            return hash;
        }
    }
    [DisallowMultipleComponent]
    public class GridLayoutGroupAdapt : AdaptBase<GridLayoutGroupAdaptConfig, GridLayoutGroup>
    {
        
        public override int Order => (int)AdapterExecuteOrder.GridLayout; 
        protected override void ApplyConfig(GridLayoutGroupAdaptConfig config) {
            base.ApplyConfig(config);
            mComponent.padding = config.padding;
            mComponent.cellSize = config.cellSize;
            mComponent.spacing = config.spacing;
            mComponent.startCorner = config.startCorner;
            mComponent.startAxis = config.startAxis;
            mComponent.childAlignment = config.childAlignment;
            mComponent.constraint = config.constraint;
            mComponent.constraintCount = config.constraintCount;
        }

        protected override void CopyProperty(GridLayoutGroupAdaptConfig config) {
            base.CopyProperty(config);
            config.padding = mComponent.padding;
            config.cellSize = mComponent.cellSize;
            config.spacing = mComponent.spacing;
            config.startCorner = mComponent.startCorner;
            config.startAxis = mComponent.startAxis;
            config.childAlignment = mComponent.childAlignment;
            config.constraint = mComponent.constraint;
            config.constraintCount = mComponent.constraintCount;
        }
    }
}


